<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改课程')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-course-edit" th:object="${course}">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="form-group">
                <label class="col-sm-3 control-label">课程名称：</label>
                <div class="col-sm-8">
                    <input name="name" th:field="*{name}" class="form-control" type="text" disabled>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">学分：</label>
                <div class="col-sm-8">
                    <input name="credit" th:field="*{credit}" class="form-control" type="text" onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')" disabled>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">学时：</label>
                <div class="col-sm-8">
                    <input name="creditHour" th:field="*{creditHour}" class="form-control" type="text" onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')" disabled>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">开课学期：</label>
                <div class="col-sm-8">
                    <input name="term" th:field="*{term}" class="form-control" type="text" disabled>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">所属教师：</label>
                <div class="col-sm-8">
                    <select name="teacherId" class="form-control m-b" th:field="*{teacherId}" disabled>
                        <option th:each="teacher : ${teacherList}" th:text="${teacher.userName}" th:value="${teacher.userId}"></option>
                    </select>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">参与班级：</label>
                <div class="col-sm-8">
                    <select class="form-control m-b" multiple id="classIds">
                        <option th:each="grade : ${classGradesList}" th:text="${grade.name}" th:value="${grade.id}"></option>
                    </select>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "system/course";
        $("#form-course-edit").validate({
            focusCleanup: true
        });

        (function () {
            var classIds = [[${course}]].classIds.split(",")
            console.log('classIds is',classIds)
            $("#classIds").val(classIds)
        })();


        function submitHandler() {
            var classIds  = $('#classIds').val()
            console.log('classIds is',classIds)
            var data = {
                "id":[[${course}]].id,
                "classIds":classIds.join(',')
            }
            console.log('data is',data)
            if ($.validate.form()) {
                $.operate.save(prefix + "/manageGrade", data);
            }
        }
    </script>
</body>
</html>
